package com.czq.zk3.controller;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import com.czq.zk3.entity.RbacUser;
import com.czq.zk3.service.RbacUserService;
import com.czq.zk3.struct.ResultLogin;
import com.czq.zk3.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：zhigao
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/user")
public class RbacUserController {
        @Autowired
    private AuthenticationManager authenticationManager;

        @Autowired
    RbacUserService userService;
        @Autowired
    RedisTemplate redisTemplate;

        @RequestMapping("getCode.png")
    public void getCode(HttpServletResponse response,String codeKey) throws IOException {
            response.setHeader("Context-type","image/jpeg");

            ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(400, 100, 4, 4);
            System.out.println(captcha.getCode());
            redisTemplate.opsForValue().set(codeKey,captcha.getCode(),1, TimeUnit.MINUTES);

            captcha.write(response.getOutputStream());
        }
        @RequestMapping("mylogin")
    public ResultLogin mylogin(@RequestBody RbacUser user,String codeKey,String code)
        {

        }
}
